import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttercalcpokers/utils/style_config.dart';

// ignore: must_be_immutable
class PublicPoker extends StatefulWidget {
  List<Map> publicPokerList;
  final selectPublicIndex;
  bool isSelectPublic;
  int publicSelectIndex;

  PublicPoker({
    Key key,
    this.publicPokerList,
    this.selectPublicIndex,
    this.isSelectPublic,
    this.publicSelectIndex,
  }) : super(key: key);

  @override
  _PublicPokerState createState() => _PublicPokerState();
}

class _PublicPokerState extends State<PublicPoker> {
  @override
  @override
  Widget build(BuildContext context) {
    Widget publicPokerBuilder() {
      List<Widget> pokers = [
        Container(
          width: ScreenUtil().setWidth(80),
          height: ScreenUtil().setHeight(80),
          alignment: Alignment.center,
          child: Text(
            "公共牌",
            style: TextStyle(
                color: color_f9f5cf,
                fontSize: fontSize_24,
                decoration: TextDecoration.none),
          ),
        ),
      ];

      int len = widget.publicPokerList.length;

      BoxDecoration _notSelect = BoxDecoration(
        border: Border.all(width: 1.0, color: Color.fromRGBO(255, 255, 255, 0)),
        borderRadius: BorderRadius.all(
          Radius.circular(4.0),
        ),
      );

      BoxDecoration _isSelect = BoxDecoration(
//        border: Border.all(width: 1.0, color: Color.fromRGBO(255, 255, 255, 1)),
        image: DecorationImage(
            image: AssetImage("images/select.png"), fit: BoxFit.cover),
        borderRadius: BorderRadius.all(
          Radius.circular(4.0),
        ),
      );

      Widget _notData = Container(
        width: ScreenUtil().setWidth(80),
        height: ScreenUtil().setHeight(100),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(
            Radius.circular(4.0),
          ),
        ),
      );

      Widget _imageBuilder(src) {
        return Container(
          width: ScreenUtil().setWidth(90),
          height: ScreenUtil().setHeight(110),
          alignment: Alignment.center,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.all(
              Radius.circular(4.0),
            ),
          ),
          child: Text(
            src,
            style: TextStyle(color: Colors.black, fontSize: fontSize_24),
          ),
        );
      }

      Widget _isSelectBuilder(item, i) {
        return Material(
          color: Color.fromRGBO(255, 255, 255, 0),
          child: InkWell(
            onTap: () {
              widget.selectPublicIndex(i);
            },
            child: Container(
              margin: EdgeInsets.zero,
              width: ScreenUtil().setWidth(100),
              height: ScreenUtil().setHeight(130),
              alignment: Alignment.center,
              decoration: widget.isSelectPublic == true &&
                      item["select"] == true &&
                      widget.publicSelectIndex == i
                  ? _isSelect
                  : _notSelect,
              child: item["src"].isNotEmpty
                  ? _imageBuilder(item["src"])
                  : _notData,
            ),
          ),
        );
      }

      for (int i = 0; i < len; i++) {
        Map item = widget.publicPokerList[i];
        pokers.add(_isSelectBuilder(item, i));
      }
      Widget content = Flex(
        direction: Axis.horizontal,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: pokers,
      );
      return content;
    }

    return Container(
        width: ScreenUtil().setWidth(750),
        height: ScreenUtil().setHeight(150),
        margin: EdgeInsets.zero,
        child: publicPokerBuilder());
  }
}
